package com.jk.service.impl;

import com.jk.mapper.AuthOrgInfoMapper;
import com.jk.service.AuthOrgInfoService;
import com.jk.vo.AuthOrgInfo;
import com.jk.vo.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by ${user} on ${data}.
 */
@Service("authOrgInfoService")
public class AuthOrgInfoServiceImpl implements AuthOrgInfoService {
    @Autowired
    private AuthOrgInfoMapper authOrgInfoMapper;
    public List<Map> SelectAuthOrgInfo(AuthOrgInfo authOrgInfo) {

        return authOrgInfoMapper.SelectAuthOrgInfo(authOrgInfo);
    }
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public int UpdateAuthOrgInfo(AuthOrgInfo authOrgInfo, WorkOrder workOrder) {

        int UpdateAuthOrgCount =authOrgInfoMapper.UpdateAuthOrgInfo(authOrgInfo);
        if(UpdateAuthOrgCount!=0){
            workOrder.setWorkoderId(UUID.randomUUID().toString().replaceAll("-", ""));
            workOrder.setWorkoderNo(UUID.randomUUID().toString().replaceAll("-", ""));
            workOrder.setWorkoderDic(1);
            workOrder.setWorkoderTime(new Date());
            authOrgInfoMapper.InsertAuthOrgInfo(workOrder); //新增修改成功
            return 1;//新增修改成功
        }else{
            return 0;//新增修改失败
        }

    }

    public AuthOrgInfo updateOrg(String id) {
        return authOrgInfoMapper.updateOrg(id);
    }

}
